import 'package:flutter/material.dart';
import '../patrol_order_list/state.dart';
import '../../../app_files.dart';
import '../../MainView/widget/main_item_widget.dart';

class PatrolOrderListWidget extends StatelessWidget {
  final PatrolListModel model;
  final Function(String, int) onLoad;
  final String tag;

  const PatrolOrderListWidget({this.onLoad, this.model, this.tag});

  Widget itemBuilder(BuildContext context, int index) {
    PatrolOrderItemModel item = model.items[index];
    return MainItemWidget.patrolItemBuilder(context, item);
  }

  @override
  Widget build(BuildContext context) {
    if (model.items == null) {
      onLoad(tag, 1);
      return Center(
        child: MyLoadingWidget(),
      );
    }
    return CustomRefreshList(
      child: model.items.length == 0
          ? Container(
        child: Center(
          child: Stack(
            children: <Widget>[
              MyEmptyItemWidget(),
            ],
          ),
        ),
      )
          : ListView.builder(
        itemBuilder: itemBuilder,
        itemCount: model.items.length,
        shrinkWrap: true,
        physics: NeverScrollableScrollPhysics(),
      ),
      onRefresh: (String tag) => onLoad(tag, 1),
      onLoading: (String tag, int page) => onLoad(tag, page),
      currentPage: model.currentPage,
      tag: tag,
      refreshController: model.refreshController,
    );
  }
}